﻿

layui.use(['element', 'layer'], function () {
    var element = layui.element;
    var layer = layui.layer;
    var ready = layer.ready;
    $(function () {
        // 从localStorage中获取父菜单索引
        var parentIndex = localStorage.getItem('ParentMenu');
        // 从localStorage中获取子菜单索引
        var childIndex = localStorage.getItem('ChildMenu');
        if (parentIndex !== null && childIndex !== null) {

            // 根据父菜单索引找到对应的父菜单元素
            var parentMenuItem = $('.layui-nav-item').eq(parseInt(parentIndex));
            // 展开父菜单
            parentMenuItem.addClass('layui-nav-itemed');

            // 根据父菜单下的子菜单索引找到对应的子菜单元素
            var childMenuItem = parentMenuItem.find('.layui-nav-child dd').eq(parseInt(childIndex));

            // 高亮显示子菜单
            childMenuItem.addClass('layui-this');
            //alert(childMenuItem)

            // 重新渲染菜单，使样式生效
            layui.use(['element'], function () {
                var element = layui.element;
                element.render('nav');
            });
        }

    })
   
     //导航点击事件
    element.on('nav(demo-filter-nav)', function (elem) {
        
        // 获取当前点击菜单所在的父菜单元素
        var parentMenuItem = $(this).parents('.layui-nav-item');
        // 获取父菜单的索引
        var parentIndex = parentMenuItem.index();
        // 获取子菜单在父菜单下的索引
        var childIndex = $(this).parent().index();
       
        localStorage.setItem('ParentMenu', parentIndex);
        localStorage.setItem('ChildMenu', childIndex);

        // 通过 element 模块的相关方法进行跳转
        element.tabChange('demo-filter-nav', $(elem).attr('href'));


        // 获取当前页面的完整路径
        var currentPageUrl = window.location.href;
        //alert($(elem).attr('href'))

        
        
    });

});